package com.zmyuan.demo.netty.thrift.codec;

import com.zmyuan.demo.netty.thrift.utils.ThriftUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * Created by zdb on 2017/2/17.
 */
public class ThriftServerEncoder extends MessageToByteEncoder<Object> {

    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
        byte[] bytes = ThriftUtils.convertThriftObjToBytes(msg);
        out.writeBytes(bytes);
        out.writeBytes(Delimiters.lineDelimiter()[0]);
    }
}
